package cmarter.dev.oracle.tutorials.models;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class Person {

    public enum Sex {
        MALE, FEMALE
    }

    private String name;
    private Calendar birthday;
    private Sex gender;
    private String emailAddress;
    

    public Person() {
		super();
	}    

    public Person(String name, Calendar birthday, Sex gender, String emailAddress) {
		super();
		this.name = name;
		this.birthday = birthday;
		this.gender = gender;
		this.emailAddress = emailAddress;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Calendar getBirthday() {
		return birthday;
	}

	public void setBirthday(Calendar birthday) {
		this.birthday = birthday;
	}

	public Sex getGender() {
		return gender;
	}

	public void setGender(Sex gender) {
		this.gender = gender;
	}

	public String getEmailAddress() {
		return emailAddress;
	}

	public void setEmailAddress(String emailAddress) {
		this.emailAddress = emailAddress;
	}

	public int getAge() {
        Calendar now = new GregorianCalendar();
        
        int age = now.get(Calendar.YEAR) - this.birthday.get(Calendar.YEAR);
        
        if ( (now.get(Calendar.MONTH) < this.birthday.get(Calendar.MONTH)) || 
        		(now.get(Calendar.MONTH) == this.birthday.get(Calendar.MONTH) &&
        		 now.get(Calendar.DAY_OF_MONTH) >= this.birthday.get(Calendar.DAY_OF_MONTH))) {
        	age--;
        }    	
    	
    	return age;
    }

    public void printPerson() {
    	System.out.println("Person: [" + "Name: " + this.name + ", DOB: " + this.birthday.toString() + "Gender: " + this.gender
    			+ "Email: " + this.emailAddress);
    }
}
